//related to view0.ui
var app = sm("do_App");
var device = sm("do_Device");
var page = sm("do_Page");
var nf = sm("do_Notification");
page.on("back", function(data) {
	app.closePage();
})
var back = ui("back_btn");
back.on("touch", function() {
	app.closePage();
})

var barcode = ui("do_BarcodeView_1");
page.on("loaded", scan);


function scan() {
	barcode.start(function(data, e) {
		device.beep();
		var mData = page.getData();
		mData.uid = data.value;
		deviceone.print(JSON.stringify(mData),"mData");
		if(mData.payType == 2){
			app.openPage({
				source:"source://view/Consumption/storedvaluedetail.ui", 
				data:mData
				});
		}else if (mData.payType == 3) {
			app.openPage({
				source:"source://view/Consumption/storedvaluedetail.ui", 
				data:mData
				});
		}else{
			//微信和支付宝接入
		}

	})
}
var flash = ui("do_Button_light");
var lightcolor = ui("do_ImageView_Lights")
var i = 0;
flash.on("touch", function() {
	i = i + 1;
	var R = i % 2;
	if (R == 1) {
		lightcolor.source = "source://image/flash_" + R + ".png";
		barcode.flash("on");
	} else if (R == 0) {
		lightcolor.source = "source://image/flash_" + R + ".png";
		barcode.flash("off");
	}
})
